Skip to content

Fix tray icon NRE: load BitmapImage from a file URI#15

Merged
StuartMeeks merged 1 commit into
masterfrom
fix/tray-icon-uri
May 30, 2026
Merged

Fix tray icon NRE: load BitmapImage from a file URI#15
StuartMeeks merged 1 commit into
masterfrom
fix/tray-icon-uri

Conversation

@StuartMeeks

@StuartMeeks StuartMeeks commented May 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • The newly-captured unhandled-exception log surfaced a NullReferenceException from H.NotifyIcon.ImageExtensions.ToStream(Uri) thrown when TaskbarIcon.IconSource is assigned.
  • Root cause: H.NotifyIcon resolves the icon by reading BitmapImage.UriSource. We were loading the identicon via SetSourceAsync(InMemoryRandomAccessStream) — pixels populated, UriSource null — so the library hit the null URI on first method call.
  • Fix: persist the deterministic identicon to %LOCALAPPDATA%\Snipdeck\tray-icon.png at tray init and construct the BitmapImage with that file URI. HNotifyIconTrayService gains an IPathProvider dependency (both already singletons in DI).

Notes

Test plan

  • Core builds clean, 106/106 tests pass.
  • Windows CI on this PR turns green.
  • Manual: launch on Windows; confirm tray icon appears with no entry in unhandled.log; right-click → context menu shows Show/Exit; left-click brings the window forward.

🤖 Generated with Claude Code

The unhandled-exception log (newly captured by PR #13) shows
H.NotifyIcon's TaskbarIcon NREs deep inside ImageExtensions.ToStream(Uri)
when IconSource is assigned. Reading the stack: H.NotifyIcon resolves
ImageSource → BitmapImage.UriSource → file URI. Our BitmapImage was
loaded via SetSourceAsync(InMemoryRandomAccessStream) — pixels present,
UriSource null — and the library passes the null URI down its conversion
chain, NREing on first method call.

Persist the identicon PNG to %LOCALAPPDATA%\Snipdeck\tray-icon.png at
init time and construct the BitmapImage with that URI. Disk cost is
negligible (one ~1 KB file at app launch), the file location is stable
across runs (deterministic identicon seed), and the shape matches what
H.NotifyIcon's resolution path expects.

HNotifyIconTrayService gains an IPathProvider dependency; both are
already singletons in the DI container so no wiring change.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@StuartMeeks StuartMeeks merged commit 69a064d into master May 30, 2026
4 checks passed
@StuartMeeks StuartMeeks deleted the fix/tray-icon-uri branch May 30, 2026 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant